<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Webservice extends MY_Controller {

    public function __construct()
    {
        
        parent::__construct();
        $this->disable_layout();
        $this->disable_view();
        $this->load->library('nusoap');
        $this->nusoap_server = new soap_server();
        $this->nusoap_server->configureWSDL('Webservice',"urn:Webservice");
        $this->nusoap_server->wsdl->addComplexType(
             "User",
            "complexType",
            "array",
            "",
            "SOAP-ENC:Array",
            array(
                "id"=>array("name"=>"id", "type"=>"xsd:int"),
                "firstname"=>array("name"=>"firstname", "type"=>"xsd:string"),
                "lastname"=>array("name"=>"lastname", "type"=>"xsd:string")
            )
        );
        $this->nusoap_server->register(
            "getUserById",
            array(),
            array("return"=>"tns:User"),
            "urn:Webservice",
            "urn:Webservice#getUserById",
            "rpc",
            "encoded",
            "Get member's info"
        );
        $this->nusoap_server->register(
            "test",
            array(
                "id" => "xsd:int",
            ),
            array("return"=>"tns:User"),
            "urn:Server",
            "urn:Server#test",
            "rpc",
            "encoded",
            "Get member's info"
        );
    }

    /**
     * Default function
     */
        function test($member_id) 
        {
            $row['id'] = '1';
            $row['firstname'] = 'fn';
            $row['lastname'] = 'ln';
            return $row;
        }
       
    public function index()
    {
        if($this->uri->rsegment(3) == "wsdl") {
            $_SERVER['QUERY_STRING'] = "wsdl";
        } else {
            $_SERVER['QUERY_STRING'] = "";
        }
        
       //$this->nusoap_server->service(file_get_contents("php://input"));
    }
    function WS_getUserById(){
        function getUserById(){
        $ci = &get_instance();
        $sql = "select * from users";
        $rs = $ci->db->query($sql);
        return $rs->result_array();
    }
    function haha(){
        return array(1,2,3);
    }
        //$this->nusoap_server->service(file_get_contents("php://input")); 
    }
    function __destruct(){
        $this->nusoap_server->service(file_get_contents("php://input"));
    }

    
}